package com.gjw.com.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gjw.com.bean.Student;
import com.gjw.com.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class MyBatisController {

    @Autowired
    StudentMapper studentMapper;

    @GetMapping("/batis01")
    public Page<Student> batis01(){
        Page<Student> page = new Page<>(1, 3);


        Page<Student> studentPage = studentMapper.selectPage(page, null);

        return studentPage;
    }

    @GetMapping("/batis02")
    public List<Student> batis02(){

        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("s_id","1432528338611060737");

//        List<Student> students = studentMapper.selectList(queryWrapper);

        HashMap<String, Object> hashMap = new HashMap<>();

        List<Student> students = studentMapper.selectList(queryWrapper);

//        studentMapper.selectMaps()
        return students;
    }

//
    @GetMapping("/batis03")
    public Student batis03(){

        Student student = new Student();
        student.setSBirth("1996-10-10");
        student.setSName("李四");
//        student.setCreateTime(new Date());
        student.setSSex("男");

        studentMapper.insert(student);
        return student;
    }


}
